import Vue from 'vue'
import App from './App.vue'
import router from './router/index'
import axios from 'axios'
import VueAxios from 'vue-axios'
import VueCookie from 'vue-cookie'
import VueJsonp from 'vue-jsonp'
import { Button, Toast, Swipe, SwipeItem, Row, Col, List, PullRefresh, Cell, CellGroup } from 'vant'

import Vconsole from 'vconsole';

import 'swiper/dist/css/swiper.css'
import vueAwesomeSwiper from 'vue-awesome-swiper'

import VueHtml2Canvas from 'vue-html2canvas';

import './assets/css/base.less'
import './assets/css/common.less'

Vue.config.productionTip = false

Vue.use(VueAxios, axios);
Vue.use(VueCookie);
Vue.use(VueJsonp);
//  按钮样式
Vue.use(Button);
//  Layout布局
Vue.use(Row).use(Col);
//  提示框
Vue.use(Toast);
//  列表
Vue.use(List);
//  下拉刷新
Vue.use(PullRefresh);
//  cell单元格
Vue.use(Cell).use(CellGroup);
//  轮播图
Vue.use(Swipe).use(SwipeItem);
Vue.use(vueAwesomeSwiper);
//  页面截图
Vue.use(VueHtml2Canvas);

//  调试工具
// let vConsole = new Vconsole();
// export default vConsole;

//  全局设置弹窗显示时间
Toast.setDefaultOptions({
  duration: 2000
});

/** 点击事件添加音频文件
 *  用法一：给发生点击事件的元素添加 clickMusic='true'属性
 *  用法二：在事件函数中通过 this.clickButton() 调用
 */
// 引入音频文件[重点]
import audio from "./../public/static/audio/shake.mp3";
Vue.prototype.clickButton = () => {
  let buttonAudio = document.getElementById('buttonAudio');
  buttonAudio.setAttribute('src', audio);
  buttonAudio.play();
}
document.body.addEventListener('click', function (e) {
  let event = e || window.event;
  let target = event.target || event.srcElement;
  let clickMusic = target.getAttribute('clickMusic')
  if (clickMusic === 'true') Vue.prototype.clickButton();
  else return false;
})

axios.interceptors.request.use(function (request) {
  //  loading、请求地址替换、修改
  return request;
});
//  {code:0,data:'',message:'}
axios.interceptors.response.use(function (response) {
  let res = response.data;
  if (res.code != 0) {
    alert(res.message);
  }
  return response;
}, function (error) {
  return Promise.reject(error);
});

new Vue({
  router,
  render: h => h(App),
}).$mount('#app')
